package org.javaboy.vhr.controller.emp;

import org.javaboy.vhr.model.Employee;
import org.javaboy.vhr.model.Employeeec;
import org.javaboy.vhr.model.Employeetrain;
import org.javaboy.vhr.service.EmployeetrainService;
import org.javaboy.vhr.vo.RespBean;
import org.javaboy.vhr.vo.RespPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/employee/train")
public class EmpTrainController {
    @Autowired
    EmployeetrainService employeetrainService;

    @GetMapping("/")
    public RespPageBean getEmployeetrainByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size, Employeetrain employeetrain, Date[] beginDateScope) {
        return employeetrainService.getEmployeeTrainByPage(page,size,employeetrain,beginDateScope);
    }

    @PostMapping("/add")
    public RespBean add(@RequestBody Employeetrain employeetrain){
        Integer i = employeetrainService.add(employeetrain);
        if(i == null) {
            return RespBean.error("操作失败");
        }else return RespBean.ok("操作成功");
    }

    @PutMapping("/")
    public RespBean updateEmp(@RequestBody Employeetrain employeetrain) {
        if (employeetrainService.update(employeetrain)==1) {
            return RespBean.ok("更新成功!");
        }
        return RespBean.error("更新失败!");
    }

    @DeleteMapping("/{id}")
    public RespBean deleteEmpByEid(@PathVariable Integer id) {
        if (employeetrainService.delete(id)==1) {
            return RespBean.ok("删除成功!");
        }
        return RespBean.error("删除失败!");
    }
}